<?php
/* **************************************************************************
File:					query.estategent.php
EstateAgent Improved - a Joomla Component

Year: 2007
Author: Manos Orfanoudakis - "vosk"
Homepage: 		http://www.eaimproved.eu
Version: 			1.3.x                      
License:			GNU/GPL http://www.gnu.org/copyleft/gpl.html
*************************************************************************** */



// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class EAQ{
	function contactInformation(&$obj){
		global $gid;
		$gq= is_numeric($gid)?"AND d.access<=$gid":"";
		$sql = "SELECT d.* FROM #__contact_details AS d LEFT JOIN  #__categories AS c ON (d.catid = c.id) WHERE d.user_id = $obj->created_by"
				." AND d.published = 1 $gq AND  c.name='EstateAgents' ";
			return $sql;
	
	}
	function countObjects($cat=""){
		global $gid;
		$today =  mosCurrentDate( $format="%Y-%m-%d" );
		$gq= is_numeric($gid)?"AND access<=$gid":"";
		//$cat=intval($cat);
		$cat= is_numeric($cat)?" AND cat = '$cat'" : "";
		$q="SELECT count(*) FROM #__estateagent" 
			. "\n WHERE"
			. "\n  ("
			. "\n ((publish_up >= '0000-00-00' AND publish_up <= '$today') AND publish_down >= '$today')"
       		. "\n OR ((publish_up >= '0000-00-00' AND publish_up <= '$today' ) AND (publish_down = '0000-00-00' OR publish_down >= '$today'))"
       		. "\n OR (publish_up = '0000-00-00' AND publish_down = '0000-00-00')"
       		. "\n )"
			. " $cat $gq  AND published=1";
		return $q;
	
	}
	function getHotObjects($amount,$cat=""){
		global $gid,$eaconf;
		$today =  mosCurrentDate( $format="%Y-%m-%d" );
		$gq= is_numeric($gid)?"AND access<=$gid":"";
		//$cat=intval($cat);
		$cat= is_numeric($cat)?" AND cat = '$cat'" : "";
		$query = "SELECT * FROM #__estateagent WHERE ("
    	   		. "\n ((publish_up >= '0000-00-00' AND publish_up <= '$today') AND publish_down >= '$today')"
       			. "\n OR ((publish_up >= '0000-00-00' AND publish_up <= '$today' ) AND (publish_down = '0000-00-00' OR publish_down >= '$today'))"
       			. "\n OR (publish_up = '0000-00-00' AND publish_down = '0000-00-00')"
       			. "\n )"
				. "\n  $cat AND hot=1 $gq AND published=1 ORDER BY created DESC"
				." LIMIT 0,$amount";

		//echo $query;
		return $query;
				
	
	}
	function countCategories($parent=""){
		global $gid;
		$today =  mosCurrentDate( $format="%Y-%m-%d" );
		$gq= is_numeric($gid)?"AND access<=$gid":"";
		//$parent=intval($parent);
		$parent= is_numeric($parent)?" AND parent = '$parent'" : "";
		return "SELECT count(id) FROM #__estateagent_categories"
    			. "\n WHERE" 
				. "\n ("
				. "\n ((publish_up >= '0000-00-00' AND publish_up <= '$today') AND publish_down >= '$today')"
       			. "\n OR ((publish_up >= '0000-00-00' AND publish_up <= '$today' ) AND (publish_down = '0000-00-00' OR publish_down >= '$today'))"
       			. "\n OR (publish_up = '0000-00-00' AND publish_down = '0000-00-00')"
       			. "\n )"
				. "  $parent AND published = 1 $gq";
	
	}
	function getCategories($parent=""){
		global $gid;
		$today =  mosCurrentDate( $format="%Y-%m-%d" );
		$gq= is_numeric($gid)?" access<=$gid AND ":"";
		//$parent=intval($parent);
		$parent= is_numeric($parent)?" AND parent = '$parent'" : "";

		return  "SELECT * FROM #__estateagent_categories " 
				. "\n WHERE $gq "
				. "\n ("
				. "\n ((publish_up >= '0000-00-00' AND publish_up <= '$today') AND publish_down >= '$today')"
       			. "\n OR ((publish_up >= '0000-00-00' AND publish_up <= '$today' ) AND (publish_down = '0000-00-00' OR publish_down >= '$today'))"
       			. "\n OR (publish_up = '0000-00-00' AND publish_down = '0000-00-00')"
       			. "\n )"
				. " $parent AND  published = 1 ORDER BY ordering ASC";	
	}
}


?>